package com.ibeeking.found.workflow.api.feign.fallback;

import com.ibeeking.found.workflow.api.common.dto.EmployeeDTO;
import com.ibeeking.found.workflow.api.common.dto.SimpleEmployeeDTO;
import com.ibeeking.found.workflow.api.common.query.EmployeeFeignQuery;
import com.ibeeking.found.workflow.api.feign.FlowEmployeeFeignBClient;
import com.ibeeking.nematos.utils.result.ResponseCodeEnum;
import com.ibeeking.nematos.utils.result.ResponseResult;
import feign.hystrix.FallbackFactory;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;

import java.util.Collections;
import java.util.List;


/**
 * 降级工场
 *
 * @Author ibeeking
 * @date 2019/1/18
 */
@Component
public class FlowEmployeeFeignBFallbackFactory implements FallbackFactory<FlowEmployeeFeignBClient> {
    @Override
    public FlowEmployeeFeignBClient create(Throwable throwable) {
        return new FlowEmployeeFeignBClient() {
            @Override
            public ResponseResult<List<EmployeeDTO>> queryEmployeeList(@RequestBody EmployeeFeignQuery query) {
                return ResponseResult.fail(ResponseCodeEnum.SYSTEM_ERROR.getCode(), "进入降级工厂，查询员工信息失败!", Collections.emptyList());
            }
            @Override
            public ResponseResult<SimpleEmployeeDTO>  queryEmployee(@PathVariable("employeeId") Long employeeId) {
                return ResponseResult.fail(ResponseCodeEnum.SYSTEM_ERROR.getCode(), "进入降级工厂，查询员工信息失败!", null);
            }
        };
    }
}
